package com.gs.SynAntiWandering.presenter;


import com.google.gson.reflect.TypeToken;
import com.gs.SynAntiWandering.apiresult.ApiResultData;
import com.gs.SynAntiWandering.apiresult.PagedList;
import com.gs.SynAntiWandering.db.dto.RecordDto;
import com.gs.SynAntiWandering.db.query.BaseQuery;
import com.gs.SynAntiWandering.model.listener.OnResultListener;
import com.gs.SynAntiWandering.model.RecordsModel;
import com.gs.SynAntiWandering.view.IRecordView;

public class RecordPresenter extends BasePresenter<IRecordView> {
    private RecordsModel recordsModel = new RecordsModel();

    public void getData(BaseQuery query) {
        recordsModel.getData(query, new OnResultListener() {
            @Override
            public void onSuccess(Object apiResult) {
                if (getView() != null) {
                    getView().onGetDataSuccess((ApiResultData<PagedList<RecordDto>>) apiResult);
                }
            }

            @Override
            public void onFails(Exception e) {
                if (getView() != null) {
                    getView().onGetDataFails(e);
                }
            }
        }, new TypeToken<ApiResultData<PagedList<RecordDto>>>() {
        }.getType());
    }
}
